import React from 'react'

import avatar from '../../assets/images/avatar.png'

class CommentAdd extends React.Component {
  state = {
    input: ''
  }

  // 发表评论按钮
  onAddComment = () => {
    // console.log('评论内容：', this.state.input, this.props)

    // 子组件调用父组件的回调函数，将数据作为函数参数，传递给父组件
    this.props.addComment(this.state.input)

    // 清空评论内容
    this.setState({
      input: ''
    })
  }

  render() {
    // console.log('CommentAdd 组件渲染了', <div>123</div>)
    console.log('CommentAdd 组件渲染了')
    return (
      <div className="comment-send">
        <div className="user-face">
          <img className="user-head" src={avatar} alt="" />
        </div>
        <div className="textarea-container">
          <textarea
            cols="80"
            rows="5"
            placeholder="发条友善的评论"
            className="ipt-txt"
            value={this.state.input}
            onChange={e => this.setState({ input: e.target.value })}
          />
          <button
            type="submit"
            className="comment-submit"
            onClick={this.onAddComment}
          >
            发表评论
          </button>
        </div>
        <div className="comment-emoji">
          <i className="face"></i>
          <span className="text">表情</span>
        </div>
      </div>
    )
  }
}

export default CommentAdd
